import { addFavorite, deleteFavorite } from "@/api/article";

export default async function(article) {
  article.favoriteDisabled = true;
  if (article.favorited) {
    const { data } = await deleteFavorite(article.slug);
    article.favorited = false;
    article.favoritesCount -= 1;
  } else {
    const { data } = await addFavorite(article.slug);
    article.favorited = true;
    article.favoritesCount += 1;
  }
  article.favoriteDisabled = false;
}
